package RevolCraft;

import RevolCraft.Blocks.BlockElectricFurnace;
import RevolCraft.Blocks.BlockGenerator;
import RevolCraft.Common.CommonProxy;
import RevolCraft.Handlers.GuiHandler;
import RevolCraft.Handlers.PacketHandler;
import RevolCraft.TileEntities.TileEntityElectricFurnace;
import RevolCraft.TileEntities.TileEntityGenerator;
import net.minecraft.src.Block;
import net.minecraft.src.CraftingManager;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.RenderItem;
import net.minecraft.src.TileEntitySpecialRenderer;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.asm.SideOnly;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(name="Revolution Craft", modid="RevolCraft", version="0.1.7")
@NetworkMod(clientSideRequired=true, serverSideRequired=false,
			clientPacketHandlerSpec = @NetworkMod.SidedPacketHandler(channels={"TileEntities"}, packetHandler=PacketHandler.class))
public class RevolCraft {
	@Instance
	public static RevolCraft instance;
	
	@SidedProxy(clientSide = "RevolCraft.Common.ClientProxy", serverSide = "RevolCraft.Common.CommonProxy")
	public static CommonProxy proxy;
	
	//Blocks
	private static Block blockGenerator;
	private static Block blockElectricFurnace;
	
	@Init
	public void init(FMLInitializationEvent event)
	{
		createBlocks();
		registerBlocks();
		registerTileEntities();
		
		NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());
	}
	
	@PreInit
	public void preInit(FMLPreInitializationEvent event)
	{
		proxy.registerRenderThings();
		proxy.loadConfig(event.getSuggestedConfigurationFile());
	}
	
	@PostInit
	public void postInit(FMLPostInitializationEvent event)
	{
		proxy.saveConfig();
	}
	
	private void createBlocks()
	{
		blockGenerator = new BlockGenerator(proxy.getConfig().get(Configuration.CATEGORY_BLOCK, "Generator", 1000).getInt(), 0);
		blockElectricFurnace = new BlockElectricFurnace(proxy.getConfig().get(Configuration.CATEGORY_BLOCK, "Electric Furnace", 1001).getInt(), 1);
	}
	
	private void registerBlocks()
	{
		GameRegistry.registerBlock(blockGenerator);
		GameRegistry.registerBlock(blockElectricFurnace);
		
		LanguageRegistry.addName(blockGenerator, "Generator");
		LanguageRegistry.addName(blockElectricFurnace, "Electric Furnace");
	}
	
	private void registerTileEntities()
	{
		GameRegistry.registerTileEntity(TileEntityGenerator.class, "TileEntityGenerator");
		GameRegistry.registerTileEntity(TileEntityElectricFurnace.class, "TileEntityElectricFurnace");
	}
}
